import axios from './axios'
/** this is get cate lists */
export const getCategorys = async (params?: object) => {
  try {
    const { data } = (await axios({
      method: 'GET',
      url: '/api/category/list',
      params,
    })) as any
    return data && data.code ? data.categories : []
  } catch (error) {
    throw error
  }
}

export const insertCategory = async (obj: object) => {
  try {
    const { data } = (await axios({
      method: 'POST',
      url: '/api/category/insert',
      data: { ...obj },
    })) as any
    return data && data.code ? data : {}
  } catch (error) {
    throw error
  }
}

export const deleteCategory = async (id: string) => {
  try {
    const { data } = (await axios({
      method: 'POST',
      url: '/api/category/delete',
      data: { id },
    })) as any
    return data && data.code ? data : {}
  } catch (error) {
    throw error
  }
}
